package com.Ivy.thread.object;
//生产者负责生产产品
public class Producer extends Thread{
    private Warehouse warehouse;
    //线程终止 :从外部创建一个终止表示变量，结束run方法，即可终止线程的运行
    private boolean stopping;
    public Producer( Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    public boolean isStopping() {
        return stopping;
    }

    public void setStopping(boolean stopping) {
        this.stopping = stopping;
    }

    //方法：生产
    public void produce() throws InterruptedException {
        this.warehouse.doProduce();
    }
    //重写Thread类的run方法
    @Override
    public void run(){
        //仓库空了，进行生产操作
        while (true){
            try {
                this.produce();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (stopping){
                break;
            }

        }

    }
}
